package matrix

// const testVersion = 1

type Pair struct {
	i int
	j int
}

func (m Matrix) Saddle() (sp []Pair) {
	var alternative []Pair

	var max, intI, intJ int
	for i := 0; i < len(m.numbers); i++ {
		max = 0
		for j := 0; j < len(m.numbers[i]); j++ {
			if max < m.numbers[i][j] {
				max = m.numbers[i][j]
				intI = i
				intJ = j
			}
		}
		alternative = append(alternative, Pair{intI, intJ})
	}

	var min int
	for _, p := range alternative {
		min = m.numbers[p.i][p.j]
		intI = p.i
		intJ = p.j
		for i := 0; i < len(m.numbers); i++ {
			if min > m.numbers[i][p.j] {
				min = m.numbers[i][p.j]
				intI = i
			}
		}
		if intI == p.i {
			sp = append(sp, p)
		}
	}

	return
}
